package io

import (
	"exp/mem"
	stdio "io"
	"unsafe"
)

func StdReader(r Reader) stdio.Reader {
	return stdReader{r}
}

type stdReader struct {
	r Reader
}

func (r stdReader) Read(p []byte) (n int, err error) {
	return r.r.Read(mem.WB(p))
}

func FromStdReader(r stdio.Reader) Reader {
	return upgradeReader{r}
}

type upgradeReader struct {
	r stdio.Reader
}

func (r upgradeReader) Read(p mem.RW) (n int, err error) {
	return r.r.Read(*(*[]byte)(unsafe.Pointer(p.UnsafeSlicePtr())))
}
